
public class p10 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		int targetN=2000000;
		long sum=5; // 2+3;
		
		for(int i=5; i<targetN; i+=2) {
			if (isPrimeF(i)) {
				sum += i;
				//System.out.println(i);
			}
		}
		System.out.println("sum: " + sum);
	}
	
	static boolean isPrimeF(long n) {
		if(n%2==0 || n%3==0) {
			return false;
		}
		
		if(n<8) {
			return isPrime(n);
		}
		
		long limit=(long) Math.sqrt(n);
		long i=0;
		
		do {
			i++;
			if (n % (6*i - 1) == 0 || n%(6*i + 1) == 0) {
				return false;
			}
		} while (6*i + 1 < limit);
			
		return true;
	}
	
	static boolean isPrime(long n) {
		for (long i = 2; i < n / 2; i++) {
			if (n % i == 0) {
				return false;
			}
		}
		return true;
	}
}
